package com.crazy.mybatis.gerenator.service.util;

import java.sql.Types;

public class TypeUtil {

	public static String getJdbcType(int columnType) {
		String jdbcType = null;
		switch (columnType) {
		case Types.BIGINT:
			jdbcType = "BIGINT";
			break;
		case Types.INTEGER:
			jdbcType = "INTEGER";
			break;
		case Types.TINYINT:
			jdbcType = "TINYINT";
			break;
		case Types.VARCHAR:
			jdbcType = "VARCHAR";
			break;	
		case Types.TIMESTAMP:
			jdbcType = "TIMESTAMP";
			break;
		default:
			jdbcType = "";
		}
		return jdbcType;
	}
	
	public static String getPropertyType(int columnType) {
		String propertyType = null;
		switch (columnType) {
		case Types.BIGINT:
			propertyType = "java.lang.Long";
			break;
		case Types.INTEGER:
			propertyType = "java.lang.Integer";
			break;
		case Types.TINYINT:
			propertyType = "java.lang.Integer";
			break;
		case Types.VARCHAR:
			propertyType = "java.lang.String";
			break;	
		case Types.TIMESTAMP:
			propertyType = "java.util.Date";
			break;
		default:
			propertyType = "Null";
		}
		return propertyType;
	}
	
	public static String getShortName(String className) {
		if (className == null) {
			return null;
		}
		int i = className.lastIndexOf(".");
		return className.substring(i + 1);
	}
	
}
